<style lang="less">
@import "./main.less";
@import "../styles/common.less";
@import "../styles/otherFonts.less";
// .ivu-modal-mask{
//   position: fixed;
//     top: 0;
//     bottom: 0;
//     left: 0;
//     right: 0;
//     background-color: rgba(239, 239, 239, 0.6);
//     height: 100%;
// }
</style>
<template>
  <div class="main" :class="{ 'main-hide-text': shrink }">
    <div
      class="sidebar-menu-con"
      :style="{
        width: shrink ? '60px' : '200px',
        overflow: shrink ? 'visible' : 'auto',
      }"
    >
      <shrinkable-menu
        :shrink="shrink"
        @on-change="handleSubmenuChange"
        :theme="menuTheme"
        :before-push="beforePush"
        :open-names="openedSubmenuArr"
        :menu-list="menuList"
      >
        <div slot="top" class="logo-con">
          <!-- 图标 -->
          <!-- <img v-show="!shrink" src="../assets/logo.jpg" key="max-logo" />
                    <img v-show="shrink" src="../assets/logo-min.jpg" key="min-logo" /> -->
        </div>
      </shrinkable-menu>
    </div>
    <div
      class="main-header-con"
      :style="{ paddingLeft: shrink ? '60px' : '200px' }"
    >
      <div class="main-header">
        <div class="navicon-con">
          <Icon
            type="md-menu"
            :style="{
              transform: 'rotateZ(' + (this.shrink ? '-90' : '0') + 'deg)',
            }"
            @click="toggleClick"
          />
        </div>
        <div class="header-middle-con">
          <div class="main-breadcrumb">
            <breadcrumb-nav :currentPath="currentPath"></breadcrumb-nav>
          </div>
        </div>

        <!-- 头部右侧内容 -->
        <div class="header-avator-con">
          <!-- <full-screen
            v-model="isFullScreen"
            @on-change="fullscreenChange"
            style=""
          ></full-screen> -->
          <!-- <lock-screen></lock-screen> -->
          <!-- 消息模块 -->
          <!-- <message-tip v-model="mesCount"></message-tip> -->
          <div class="user-dropdown-menu-con">
            <Row
              type="flex"
              justify="end"
              align="middle"
              class="user-dropdown-innercon"
            >
              <!-- 个人中心模块 -->
              <Dropdown
                transfer
                trigger="click"
                @on-click="handleClickUserDropdown"
                placement="bottom-end"
              >
                <a href="javascript:void(0)">
                  <div class="main-user-name">
                    <div>
                      <div>{{ userName }}</div>
                      <div>{{ departmentName }}</div>
                    </div>
                    <div>
                      <Icon
                        type="ios-arrow-down"
                        style="margin-left: 10px"
                      ></Icon>
                    </div>
                  </div>
                </a>
                <DropdownMenu slot="list">
                  <!-- divided -->
                  <DropdownItem name="ownSpace">个人中心</DropdownItem>
                  <DropdownItem name="loginout">退出登录</DropdownItem>
                </DropdownMenu>
              </Dropdown>
              <!-- <Avatar :src="avatorPath" style="background: #619fe7;margin-left: 10px;"></Avatar> -->
            </Row>
          </div>
        </div>
      </div>
      <!-- <div class="tags-con">
        <tags-page-opened :pageTagsList="pageTagsList"></tags-page-opened>
      </div> -->
    </div>
    <div class="single-page-con" :style="{ left: shrink ? '60px' : '200px' }">
      <div class="single-page">
        <!-- <keep-alive :include="cachePage"> -->
        <router-view ></router-view>
        <!-- </keep-alive> -->
      </div>
    </div>
  </div>
</template>
<script>
import shrinkableMenu from "./main-components/shrinkable-menu/shrinkable-menu.vue";
import tagsPageOpened from "./main-components/tags-page-opened.vue";
import breadcrumbNav from "./main-components/breadcrumb-nav.vue";
import fullScreen from "./main-components/fullscreen.vue";
import lockScreen from "./main-components/lockscreen/lockscreen.vue";
// import messageTip from './main-components/message-tip.vue';
import Cookies from "js-cookie";
import util from "@/libs/util.js";
import axios from "axios";
export default {
  components: {
    shrinkableMenu,
    tagsPageOpened,
    breadcrumbNav,
    fullScreen,
    lockScreen,
    // messageTip,
  },
  data() {
    return {
      shrink: false,
      userName: "",
      departmentName: "",
      isFullScreen: false,
      openedSubmenuArr: this.$store.state.app.openedSubmenuArr,
      menuList: [],
    };
  },
  computed: {
    pageTagsList() {
      return this.$store.state.app.pageOpenedList; // 打开的页面的页面对象
    },
    currentPath() {
      return this.$store.state.app.currentPath; // 当前面包屑数组
    },
    avatorPath() {
      return localStorage.avatorImgPath;
    },
    cachePage() {
      return this.$store.state.app.cachePage;
    },
    lang() {
      return this.$store.state.app.lang;
    },
    menuTheme() {
      return this.$store.state.app.menuTheme;
    },
    mesCount() {
      return this.$store.state.app.messageCount;
    },
  },
  methods: {
    init() {
      //   let pathArr = util.setCurrentPath(this, this.$route.name);
      //   this.$store.commit("app/updateMenulist");
      //   if (pathArr.length >= 2) {
      //     this.$store.commit("app/addOpenSubmenu", pathArr[1].name);
      //   }
      this.userName = JSON.parse(sessionStorage.getItem("userdata")).name;
      this.departmentName = JSON.parse(
        sessionStorage.getItem("userdata")
      ).departmentName;
      // {"id":"1","username":"管理员","departmentName":"区市场监管局（知识产权局）","isAdmin":true}
      let messageCount = 3;
      this.messageCount = messageCount.toString();
      this.checkTag(this.$route.name);
      this.$store.commit("app/setMessageCount", 3);
    },
    toggleClick() {
      this.shrink = !this.shrink;
    },
    handleClickUserDropdown(name) {
      if (name === "ownSpace") {
        util.openNewPage(this, "ownspace_index");
        this.$router.push({
          name: "ownspace_index",
        });
      } else if (name === "loginout") {
        // 退出登录
        localStorage.clear();
        sessionStorage.clear();
        Cookies.remove("locking");
        this.$router.replace({
          name: "home",
        });
        // axios.post("/hlapi/Auth/Logout").then((res) => {
        //   localStorage.clear();
        //   sessionStorage.clear();
        //   Cookies.remove("locking");
        //   this.$router.replace({
        //     name: "login",
        //   });
        // });
      }
    },
    checkTag(name) {
      let openpageHasTag = this.pageTagsList.some((item) => {
        if (item.name === name) {
          return true;
        }
      });
      if (!openpageHasTag) {
        //  解决关闭当前标签后再点击回退按钮会退到当前页时没有标签的问题
        util.openNewPage(
          this,
          name,
          this.$route.params || {},
          this.$route.query || {}
        );
      }
    },
    handleSubmenuChange(val) {},
    beforePush(name) {
      // if (name === 'accesstest_index') {
      //     return false;
      // } else {
      //     return true;
      // }
      return true;
    },
    fullscreenChange(isFullScreen) {},
    menuListInit() {
      const tempArr = JSON.parse(sessionStorage.getItem("canRouterList"));
      const tempArr2 = JSON.parse(
        JSON.stringify(this.$store.state.app.menuList)
      );

      this.menuList = util.menuListOp(tempArr2, tempArr);

      // this.menuList=this.$store.state.app.menuList
    },
  },
  watch: {
    $route(to) {
      this.$store.commit("app/setCurrentPageName", to.name);
      const pathArr = util.setCurrentPath(this, to.name);
      if (pathArr.length > 2) {
        this.$store.commit("app/addOpenSubmenu", pathArr[1].name);
      }
      this.checkTag(to.name);
      localStorage.currentPageName = to.name;
    },
    lang() {
      util.setCurrentPath(this, this.$route.name); // 在切换语言时用于刷新面包屑
    },
  },
  mounted() {
    this.init();
    this.menuListInit();
  },
  created() {
    // 显示打开的页面的列表
    this.$store.commit("app/setOpenedList");
  },
};
</script>
